#include <sys_config.h>
#include <types.h>
#include <basic_types.h>
#include <mediatypes.h>
#include <api/libc/printf.h>
#include <api/libc/string.h>
#include <osal/osal.h>

#include <api/libosd/osd_lib.h>

#include "osdobjs_def.h"

#include "string.id"
#include "images.id"
#include "osd_config.h"
#include "osd_rsc.h"

#include "copper_common/system_data.h"
#include "copper_common/menu_api.h"
#include "win_com_menu_define.h"
#include "win_com.h"
#include "win_com_popup.h"

/*******************************************************************************
*	Objects definition
*******************************************************************************/
extern CONTAINER win_parental_con;

extern CONTAINER par_item_con1;
extern CONTAINER par_item_con2;
extern CONTAINER par_item_con3;
extern CONTAINER par_item_con4;
extern CONTAINER par_item_con5;

extern TEXT_FIELD par_item_txtname1;
extern TEXT_FIELD par_item_txtname2;
extern TEXT_FIELD par_item_txtname3;
extern TEXT_FIELD par_item_txtname4;
extern TEXT_FIELD par_item_txtname5;

extern TEXT_FIELD par_item_txtset1;
extern TEXT_FIELD par_item_txtset2;
extern TEXT_FIELD par_item_txtset3;
extern TEXT_FIELD par_item_txtset4;
extern TEXT_FIELD par_item_txtset5;

extern TEXT_FIELD par_item_line0;
extern TEXT_FIELD par_item_line1;
extern TEXT_FIELD par_item_line2;

static VACTION par_item_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT par_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);

static VACTION par_con_keymap(POBJECT_HEAD pObj, UINT32 key);
static PRESULT par_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2);


#define LDEF_CON(root, varCon,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,conobj,focusID)		\
    DEF_CONTAINER(varCon,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, CON_SH_IDX,CON_HL_IDX,CON_SL_IDX,CON_GRY_IDX,   \
    par_item_con_keymap,par_item_con_callback,  \
    conobj, focusID,1)

#define LDEF_TXTNAME(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, TXTN_SH_IDX,TXTN_HL_IDX,TXTN_SL_IDX,TXTN_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_LEFT | C_ALIGN_VCENTER, 0,0,resID,str)

#define LDEF_TXTSET(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, TXTS_SH_IDX,TXTS_HL_IDX,TXTS_SL_IDX,TXTS_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 20,0,resID,str)

#define LDEF_TXTSET2(root,varTxt,nxtObj,ID,IDl,IDr,IDu,IDd,l,t,w,h,resID,str)		\
    DEF_TEXTFIELD(varTxt,root,nxtObj,C_ATTR_ACTIVE,0, \
    ID,IDl,IDr,IDu,IDd, l,t,w,h, TXTS_SH_IDX,WSTL_BUTTON_05_HD,TXTS_SL_IDX,TXTS_GRY_IDX,   \
    NULL,NULL,  \
    C_ALIGN_CENTER| C_ALIGN_VCENTER, 20,0,resID,str)

#define LDEF_MM_ITEM(root,varCon,nxtObj,varTxtName,varTxtset,varLine,ID,IDu,IDd,l,t,w,h,nameID,setstr)	\
	LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxtName,1)	\
	LDEF_TXTNAME(&varCon,varTxtName,&varTxtset,0,0,0,0,0,l + TXTN_L_OF, t + TXTN_T_OF,TXTN_W,TXTN_H,nameID,NULL)	\
	LDEF_TXTSET(&varCon,varTxtset,  NULL/*&varLine*/,1,1,1,1,1,l + TXTS_L_OF, t + TXTS_T_OF,TXTS_W,TXTS_H,0,setstr) \
    LDEF_LINE(&varCon,varLine,NULL,1,1,1,1,1,l + LINE_L_OF, t + LINE_T_OF,LINE_W,LINE_H,0,0)
    
#define LDEF_MM_ITEM2(root,varCon,nxtObj,varTxtName,varTxtset,ID,IDu,IDd,l,t,w,h,nameID,setstr)	\
	LDEF_CON(&root,varCon,nxtObj,ID,ID,ID,IDu,IDd,l,t,w,h,&varTxtName,1)	\
	LDEF_TXTNAME(&varCon,varTxtName,&varTxtset,0,0,0,0,0,l + TXTN_L_OF, t + TXTN_T_OF,TXTN_W,TXTN_H,nameID,NULL)	\
	LDEF_TXTSET2(&varCon,varTxtset,  NULL        ,1,1,1,1,1,l + TXTS_L_OF, t + TXTS_T_OF,TXTS_W,TXTS_H,0,setstr)

LDEF_MM_ITEM(win_parental_con,par_item_con1, &par_item_con2,par_item_txtname1,par_item_txtset1,par_item_line0,1,4,2,	\
				CON_L, CON_T + (CON_H + CON_GAP)*0,CON_W,CON_H,	RS_SYSTME_PARENTAL_LOCK_MENU_LOCK,NULL)
LDEF_MM_ITEM(win_parental_con,par_item_con2, &par_item_con3,par_item_txtname2,  par_item_txtset2,par_item_line1,2,1,3,	\
				CON_L, CON_T + (CON_H + CON_GAP)*1,CON_W,CON_H,	RS_PARENTAL_RATING_LOCK/*RS_SYSTME_PARENTAL_LOCK_CHANNEL_LOCK*/,NULL)
LDEF_MM_ITEM(win_parental_con,par_item_con3, &par_item_con4,par_item_txtname3,  par_item_txtset3,par_item_line2,3,2,4,	\
				CON_L, CON_T + (CON_H + CON_GAP)*2,CON_W,CON_H,	RS_PARENTAL_CONTENT_LOCK,NULL)
LDEF_MM_ITEM2(win_parental_con,par_item_con4, &par_item_con5,par_item_txtname4,par_item_txtset4,4,3,5,	\
				CON_L, CON_T + (CON_H + CON_GAP)*3,CON_W,CON_H,	RS_SYSTME_PARENTAL_LOCK_NEW_PASSWORD,display_strs[0])
LDEF_MM_ITEM2(win_parental_con,par_item_con5, NULL,par_item_txtname5,par_item_txtset5,5,4,1,	\
				CON_L, CON_T + (CON_H + CON_GAP)*4,CON_W,CON_H,	RS_SYSTME_PARENTAL_LOCK_CONFIRM_PASSWORD,display_strs[1])

DEF_CONTAINER(win_parental_con,NULL,NULL,C_ATTR_ACTIVE,0, \
    1,0,0,0,0, W_L,W_T,W_W,W_H, WIN_SH_IDX,WIN_HL_IDX,WIN_SL_IDX,WIN_GRY_IDX,   \
    par_con_keymap,par_con_callback,  \
    (POBJECT_HEAD)&par_item_con1, 1,0)

UINT32		win_pl_password_value[2];
UINT8		g_PL_Input_Bit_Number;
UINT8		g_PL_Input_Status;

/*******************************************************************************
*	Local functions & variables define
*******************************************************************************/
CONTAINER* par_items[] =
{
	&par_item_con1,
	&par_item_con2,
	&par_item_con3,
	&par_item_con4,
	&par_item_con5,
};

POBJECT_HEAD par_item_name[] =
{
	(POBJECT_HEAD)&par_item_txtname1,
	(POBJECT_HEAD)&par_item_txtname2,
	(POBJECT_HEAD)&par_item_txtname3,
	(POBJECT_HEAD)&par_item_txtname4,
	(POBJECT_HEAD)&par_item_txtname5,
};

POBJECT_HEAD par_item_set[] =
{
	(POBJECT_HEAD)&par_item_txtset1,
	(POBJECT_HEAD)&par_item_txtset2,
	(POBJECT_HEAD)&par_item_txtset3,
	(POBJECT_HEAD)&par_item_txtset4,
	(POBJECT_HEAD)&par_item_txtset5,
};

#define MENU_LOCK_STREAM_NUMBER 2

#ifdef PARENTAL_SUPPORT
#ifndef POLAND_SPEC_SUPPORT
UINT16 stream_rating_str_ids[] = /*CSA only 4 level for rating control -10,-12,-16,-18*/
{
	RS_COMMON_OFF,   
   	RS_PARENTAL_AGE_10,
	RS_PARENTAL_AGE_12,
	RS_PARENTAL_AGE_14,
	RS_PARENTAL_AGE_16,	
	RS_PARENTAL_AGE_18,
};
#else
UINT16 stream_rating_str_ids[] = 
{
	RS_COMMON_OFF,   
   	RS_PARENTAL_AGE_7,
	RS_PARENTAL_AGE_12,
	RS_PARENTAL_AGE_16,	
	RS_PARENTAL_AGE_18,
};
#endif
#define MENU_RATING_STREAM_NUMBER (sizeof(stream_rating_str_ids)/2)

UINT16 stream_content_str_ids[] =
{
	RS_COMMON_OFF,
   	RS_PARENTAL_DRUGS,
   	RS_PARENTAL_VIOLENCE,
   	RS_PARENTAL_SEX,
   	RS_PARENTAL_VIOLENCE_DRUGS,
   	RS_PARENTAL_SEX_DRUGS,
   	RS_PARENTAL_VIOLENCE_SEX,
   	RS_PARENTAL_VIOLENCE_SEX_DRUGS,
};
#define MENU_CONTENT_STREAM_NUMBER (sizeof(stream_content_str_ids)/2)

#endif
void win_par_set_menu_lock_string(UINT8 input)
{
	if(input==0)
		OSD_SetTextFieldContent(&par_item_txtset1, STRING_ID,RS_COMMON_OFF);				
	else
		OSD_SetTextFieldContent(&par_item_txtset1, STRING_ID,RS_COMMON_ON);	
}

void win_par_set_channel_lock_string(UINT8 input)
{
#ifdef PARENTAL_SUPPORT
	OSD_SetTextFieldContent(&par_item_txtset2, STRING_ID,stream_rating_str_ids[input]);	
#else
	if(input==0)
		OSD_SetTextFieldContent(&par_item_txtset2, STRING_ID,RS_COMMON_OFF);				
	else
		OSD_SetTextFieldContent(&par_item_txtset2, STRING_ID,RS_COMMON_ON);	
#endif
}

void win_par_set_content_lock_string(UINT8 input)
{
#ifdef PARENTAL_SUPPORT
	OSD_SetTextFieldContent(&par_item_txtset3, STRING_ID,stream_content_str_ids[input]);	
#else
	if(input==0)
		OSD_SetTextFieldContent(&par_item_txtset3, STRING_ID,RS_COMMON_OFF);				
	else
		OSD_SetTextFieldContent(&par_item_txtset3, STRING_ID,RS_COMMON_ON);
#endif
}

void win_par_switch_confirm(BOOL flag)
{
	UINT8 action;

	if(flag)
		action = C_ATTR_ACTIVE;
	else
		action = C_ATTR_INACTIVE;

	if( !OSD_CheckAttr(&par_item_con5, action))
	{
		OSD_SetAttr(&par_item_con5, action);
		OSD_SetAttr(&par_item_txtname5, action);
		OSD_SetAttr(&par_item_txtset5, action);
		OSD_DrawObject((POBJECT_HEAD )&par_item_con5,C_DRAW_SIGN_EVN_FLG | C_UPDATE_ALL);
	}

}

void win_pl_set_password_str(UINT8 index)
{
	UINT8 temp[5];
	if((g_PL_Input_Status==TRUE)&&(g_PL_Input_Bit_Number>0))
	{
		switch(g_PL_Input_Bit_Number)
		{
			case 1:
				sprintf(temp, "*---");
				break;
			case 2:
				sprintf(temp, "**--");
				break;
			case 3:
				sprintf(temp, "***-");
				break;
			case 4:
				sprintf(temp, "****");
				break;
		}
	}
	else
	{
		sprintf(temp, "----");
	}
	#ifdef BIDIRECTIONAL_OSD_STYLE
	if (OSD_GetMirrorFlag() == TRUE)
	{
		UINT8 i, tmp;
		for (i=0; i<2; i++)
		{
			tmp = temp[i];
			temp[i] = temp[3-i];
			temp[3-i] = tmp;
		}
	}
	#endif
	ComAscStr2Uni(temp, display_strs[index]);
}

/*******************************************************************************
*	key mapping and event callback definition
*******************************************************************************/

static VACTION par_item_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
	case V_KEY_RIGHT:
		act = VACT_INCREASE;
		break;		
	case V_KEY_LEFT:		
		act = VACT_DECREASE;
		break;		
	case V_KEY_ENTER:
		act = VACT_ENTER;
		break;	
	case V_KEY_0:	case V_KEY_1:	case V_KEY_2:	case V_KEY_3:
	case V_KEY_4:	case V_KEY_5:	case V_KEY_6:	case V_KEY_7:
	case V_KEY_8:	case V_KEY_9:
		if((OSD_GetFocusID((POBJECT_HEAD)&win_parental_con)==MENU_PARENTAL_PASSWORD)||(OSD_GetFocusID((POBJECT_HEAD)&win_parental_con)==MENU_PARENTAL_PASSWORD2))
			act = VACT_NUM_0+(key-V_KEY_0);
		else
			act = VACT_PASS;
		break;			
	default:	
		act = VACT_PASS;
		break;
	}

	return act;

}

void win_par_left_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();
	UINT8 age=0;
	UINT8 content=0;
	
	age=p_sys_data->rating_sel&0xf;
	content=p_sys_data->rating_sel>>4;
	
	switch(id)
	{
		case MENU_PARENTAL_MENU_LOCK:
			p_sys_data->menu_lock=1-p_sys_data->menu_lock;
			win_par_set_menu_lock_string(p_sys_data->menu_lock);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PARENTAL_CHANNEL_LOCK:
			if(age==0)			
				age=MENU_RATING_STREAM_NUMBER-1;			
			else			
				age--;			
			p_sys_data->rating_sel = (p_sys_data->rating_sel&0xf0)|age;
			win_par_set_channel_lock_string(age);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PARENTAL_CONTENT_LOCK:
			/* need Sam to separate (UINT8)rating_sel */
			if(content==0)			
				content=MENU_CONTENT_STREAM_NUMBER-1;			
			else			
				content--;			

			p_sys_data->rating_sel = (content<<4) | (p_sys_data->rating_sel&0xf);
			win_par_set_content_lock_string(content);//bit4~bit7
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
	}
}

void win_par_right_key(POBJECT_HEAD pObj,UINT8 id)
{
	SYSTEM_DATA* p_sys_data=sys_data_get();

	UINT8 age=0;
	UINT8 content=0;	
	age=p_sys_data->rating_sel&0xf;
	content=p_sys_data->rating_sel>>4;
	
	switch(id)
	{
		case MENU_PARENTAL_MENU_LOCK:
			p_sys_data->menu_lock=1-p_sys_data->menu_lock;
			win_par_set_menu_lock_string(p_sys_data->menu_lock);
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PARENTAL_CHANNEL_LOCK:
			if(age==(MENU_RATING_STREAM_NUMBER-1))
				age=0;
			else
				age++;
		
			p_sys_data->rating_sel = (p_sys_data->rating_sel&0xf0)|age;
			win_par_set_channel_lock_string(age);
			
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
		case MENU_PARENTAL_CONTENT_LOCK:
			/* need Sam to separate (UINT8)rating_sel */
			if(content==(MENU_CONTENT_STREAM_NUMBER-1))
				content = 0;
			else
				content++;

			p_sys_data->rating_sel = (content<<4) | (p_sys_data->rating_sel&0xf);
			win_par_set_content_lock_string(content);//bit4~bit7
			
			OSD_TrackObject(pObj,C_UPDATE_ALL);
			break;
	}
}

void win_par_enter_key(POBJECT_HEAD pObj, UINT8 id)
{
	OSD_RECT rect;
	COM_POP_LIST_PARAM_T param;
	UINT8 sel=0;
	SYSTEM_DATA* p_sys_data = sys_data_get();

#if Maker_GUI_ON
	rect.uTop=Maker_GUI_SM_T;
	rect.uLeft=Maker_GUI_MM_L+(Maker_GUI_SM_W/2);
	rect.uHeight=300;
	rect.uWidth=(Maker_GUI_SM_W/2);
#else
	rect.uLeft = CON_L+TXTS_L_OF;
	rect.uWidth = TXTS_W;
	rect.uHeight = 150;
#endif	
	param.selecttype = POP_LIST_SINGLESELECT;
	
	switch (id)
	{
		case MENU_PARENTAL_MENU_LOCK:
#if Maker_GUI_ON
#else		
			rect.uTop = CON_T;
#endif			
			param.cur = p_sys_data->menu_lock;
			p_sys_data->menu_lock = win_com_open_sub_list(POP_LIST_MENU_PARENTAL_MENU_LOCK, &rect, &param);
			win_par_set_menu_lock_string(p_sys_data->menu_lock);
			break;
		case MENU_PARENTAL_CHANNEL_LOCK:
#if Maker_GUI_ON
#else		
			rect.uTop = CON_T + (CON_H + CON_GAP)*1;
#endif			
			param.cur = p_sys_data->rating_sel&0xf;
			sel = win_com_open_sub_list(POP_LIST_MENU_PARENTAL_CHANNEL_LOCK, &rect, &param);
			p_sys_data->rating_sel = (p_sys_data->rating_sel&0xf0)|sel;
			win_par_set_channel_lock_string(sel);
			break;
		case MENU_PARENTAL_CONTENT_LOCK:
#if Maker_GUI_ON
#else		
			rect.uWidth = TXTS_W+20;
			rect.uTop = CON_T + (CON_H + CON_GAP)*2;
#endif			
			param.cur = p_sys_data->rating_sel>>4;
			sel = win_com_open_sub_list(POP_LIST_MENU_PARENTAL_CONTENT_LOCK, &rect, &param);
			p_sys_data->rating_sel = (sel<<4)|(p_sys_data->rating_sel&0xf);
			win_par_set_content_lock_string(sel);
			break;
	}
	OSD_TrackObject(pObj,C_UPDATE_ALL);
}

UINT8 win_parental_get_osd_num()
{
	UINT8 id;
	
	id = OSD_GetFocusID((POBJECT_HEAD)&win_parental_con);
	switch (id)
	{
		case MENU_PARENTAL_MENU_LOCK:
			return MENU_LOCK_STREAM_NUMBER;
		case MENU_PARENTAL_CHANNEL_LOCK:
			return MENU_RATING_STREAM_NUMBER;
		case MENU_PARENTAL_CONTENT_LOCK:
			return MENU_CONTENT_STREAM_NUMBER;
	}
	return 0;
}


PRESULT comlist_menu_parental_osd_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	UINT16 i, wTop;
	UINT8 id;
	char str_len;
    	OBJLIST* ol;
	
	PRESULT cbRet = PROC_PASS;

    	ol = (OBJLIST*)pObj;
	
	if (event == EVN_PRE_DRAW)
	{
		id = OSD_GetFocusID((POBJECT_HEAD)&win_parental_con);
		wTop = OSD_GetObjListTop(ol);
		switch (id)
		{
			case MENU_PARENTAL_MENU_LOCK:
				win_comlist_set_str(0, NULL, NULL, RS_COMMON_OFF);
				win_comlist_set_str(1, NULL, NULL, RS_COMMON_ON);
				break;
			case MENU_PARENTAL_CHANNEL_LOCK:
				for (i=0; i<ol->wDep && (i+wTop)<ol->wCount; i++)
				{
					win_comlist_set_str(i+wTop, NULL, NULL, stream_rating_str_ids[i+wTop]);
				}
				break;
			case MENU_PARENTAL_CONTENT_LOCK:
				for (i=0; i<ol->wDep && (i+wTop)<ol->wCount; i++)
				{
					win_comlist_set_str(i+wTop, NULL, NULL, stream_content_str_ids[i+wTop]);
				}
				break;
		}
	}
	else if (event == EVN_POST_CHANGE)
		cbRet = PROC_LEAVE;

	return cbRet;
}

void win_pl_input_number(UINT8 item,UINT8 number)
{
	if(g_PL_Input_Status==TRUE)
	{
		switch(g_PL_Input_Bit_Number)
		{
			case 0:
			case 4:
				win_pl_password_value[item]=number;
				g_PL_Input_Bit_Number=1;
				break;
			case 1:
			case 2:
			case 3:
				win_pl_password_value[item]=number+win_pl_password_value[item]*10;
				g_PL_Input_Bit_Number++;
				break;
		}
	}
	else
	{
		g_PL_Input_Status=TRUE;
		win_pl_password_value[item]=number;
		g_PL_Input_Bit_Number=1;
	}
}

static PRESULT par_item_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT8	unact,input,save;
	UINT8	id = OSD_GetObjID(pObj);
	SYSTEM_DATA* p_sys_data=sys_data_get();

	switch(event)
	{		
	case EVN_FOCUS_PRE_GET:
		break;
		
	case EVN_FOCUS_PRE_LOSE:
		break;

	case EVN_UNKNOWN_ACTION:
		unact = (VACTION)(param1>>16) ;
		if(unact == VACT_DECREASE)
		{
			win_par_left_key(pObj,id);
		}
		else if(unact == VACT_INCREASE)
		{
			win_par_right_key(pObj,id);
		}
		else if(unact == VACT_ENTER)
		{
			win_par_enter_key(pObj,id);
		}
		else if(unact <= VACT_NUM_9)
		{
			if((g_PL_Input_Status==TRUE)&&(g_PL_Input_Bit_Number==3))
			{
				if(id==MENU_PARENTAL_PASSWORD)
				{
					win_pl_input_number(0,(UINT8)(unact-VACT_NUM_0));
					win_pl_set_password_str(0);
					win_par_switch_confirm(TRUE);
					g_PL_Input_Bit_Number=0;
					g_PL_Input_Status=FALSE;
					win_pl_password_value[1]=0;
					win_pl_set_password_str(1);
					OSD_ChangeFocus((POBJECT_HEAD)&win_parental_con,MENU_PARENTAL_PASSWORD2,C_UPDATE_ALL);
					OSD_DrawObject((POBJECT_HEAD)&par_item_con4, C_UPDATE_ALL);
					OSD_TrackObject((POBJECT_HEAD)&par_item_con5,C_UPDATE_ALL);
				}
				else
				{
					win_pl_input_number(1,(UINT8)(unact-VACT_NUM_0));
					if(win_pl_password_value[0]==win_pl_password_value[1])
					{
						win_pl_set_password_str(1);
						OSD_TrackObject(pObj,C_UPDATE_ALL);
						
						win_compopup_init(WIN_POPUP_TYPE_OK);
						win_compopup_set_msg(NULL,NULL,RS_MSG_CHANGE_PASSWORD_SUCCESS);
						#ifndef SD_UI
						win_compopup_set_frame(GET_MID_L(550),GET_MID_T(220),550,200);
						#endif
						win_compopup_open_ext(&save);
						p_sys_data->menu_password=win_pl_password_value[0];
						return PROC_LEAVE;
					}
					else
					{
						g_PL_Input_Bit_Number=0;
						g_PL_Input_Status=FALSE;
						win_pl_password_value[1]=0;
						win_pl_set_password_str(1);
						OSD_TrackObject(pObj,C_UPDATE_ALL);
					}
				}
			}
			else
			{
				win_pl_input_number(id-MENU_PARENTAL_PASSWORD,(UINT8)(unact-VACT_NUM_0));
				win_pl_set_password_str(id-MENU_PARENTAL_PASSWORD);
				OSD_TrackObject(pObj,C_UPDATE_ALL);
			}
		}
		ret = PROC_LOOP;
		break;
	}
	return ret;

}

static VACTION par_con_keymap(POBJECT_HEAD pObj, UINT32 key)
{
	VACTION act;
	
	switch(key)
	{
	case V_KEY_UP:
		if(OSD_GetFocusID((POBJECT_HEAD)&win_parental_con)==MENU_PARENTAL_PASSWORD)
		{
			g_PL_Input_Bit_Number=0;
			g_PL_Input_Status=FALSE;
			win_pl_password_value[0]=0;
			win_pl_set_password_str(0);
		}
		else if(OSD_GetFocusID((POBJECT_HEAD)&win_parental_con)==MENU_PARENTAL_PASSWORD2)
		{
			g_PL_Input_Bit_Number=0;
			g_PL_Input_Status=FALSE;
			win_pl_password_value[0]=0;
			win_pl_password_value[1]=0;
			win_pl_set_password_str(0);
			win_pl_set_password_str(1);
			win_par_switch_confirm(FALSE);
			OSD_ChangeFocus((POBJECT_HEAD)&win_parental_con,MENU_PARENTAL_PASSWORD,C_UPDATE_ALL);
			OSD_TrackObject((POBJECT_HEAD)&par_item_con4,C_UPDATE_ALL);
			act = VACT_PASS;
			break;
		}
		act = VACT_CURSOR_UP;
		break;
		
	case V_KEY_DOWN:
		if(OSD_GetFocusID((POBJECT_HEAD)&win_parental_con)==MENU_PARENTAL_PASSWORD)
		{
			g_PL_Input_Bit_Number=0;
			g_PL_Input_Status=FALSE;
			win_pl_password_value[0]=0;
			win_pl_set_password_str(0);
		}
		else if(OSD_GetFocusID((POBJECT_HEAD)&win_parental_con)==MENU_PARENTAL_PASSWORD2)
		{
			g_PL_Input_Bit_Number=0;
			g_PL_Input_Status=FALSE;
			win_pl_password_value[0]=0;
			win_pl_password_value[1]=0;
			win_pl_set_password_str(0);
			win_pl_set_password_str(1);
			win_par_switch_confirm(FALSE);
			OSD_ChangeFocus((POBJECT_HEAD)&win_parental_con,MENU_PARENTAL_MENU_LOCK,C_UPDATE_ALL);
			OSD_TrackObject((POBJECT_HEAD)&par_item_con1,C_UPDATE_ALL);
			OSD_DrawObject((POBJECT_HEAD)&par_item_con4, C_UPDATE_ALL);
			act = VACT_PASS;
			break;
		}
		act = VACT_CURSOR_DOWN;
		break;
	case V_KEY_ENTER:
		act = VACT_ENTER;
		break;		
		
	case V_KEY_EXIT:
	case V_KEY_MENU:
		act = VACT_CLOSE;
		break;
		
	default:	
		act = VACT_PASS;
		break;
	}

	return act;
}

static PRESULT par_con_callback(POBJECT_HEAD pObj, VEVENT event, UINT32 param1, UINT32 param2)
{
	PRESULT ret = PROC_PASS;
	UINT32 i;
	UINT8	unact;
	CONTAINER* cont = (CONTAINER*)pObj;
	UINT8	id = OSD_GetObjID(pObj);
	SYSTEM_DATA* p_sys_data;

	static UINT32 default_key_exit[] = 
	{
		V_KEY_EXIT,V_KEY_MENU,V_KEY_LEFT,V_KEY_UP,V_KEY_DOWN
	};
	
	switch(event)
	{
	case EVN_PRE_OPEN:
#ifndef ISDBT_SUPPORT
		remove_menu_item(cont, (OBJECT_HEAD *)par_items[2], CON_H + CON_GAP);
#endif
#ifdef _S3281_
		remove_menu_item(cont, (OBJECT_HEAD *)par_items[1], CON_H + CON_GAP);
#endif
		if(win_pwd_open(default_key_exit,ARRAY_SIZE(default_key_exit))==FALSE)
		{
			return PROC_LEAVE;
		}
		wincom_open_title((POBJECT_HEAD)&win_parental_con,RS_SYSTME_PARENTAL_LOCK, 0);
		OSD_ChangeFocus((POBJECT_HEAD)&win_parental_con,MENU_PARENTAL_MENU_LOCK,0);
		p_sys_data=sys_data_get();
		win_par_set_menu_lock_string(p_sys_data->menu_lock);
		/* need Sam to separate (UINT8)rating_sel */
		win_par_set_channel_lock_string(p_sys_data->rating_sel&0x0f);
		win_par_set_content_lock_string(p_sys_data->rating_sel>>4);
		win_par_switch_confirm(FALSE);
		g_PL_Input_Bit_Number=0;
		g_PL_Input_Status=FALSE;
		win_pl_password_value[0]=0;
		win_pl_password_value[1]=0;
		win_pl_set_password_str(0);
		win_pl_set_password_str(1);
		break;
	
	case EVN_POST_OPEN:
		break;
		
	case EVN_PRE_CLOSE:
		sys_data_save(1);
        *((UINT32*)param2) &= ~C_CLOSE_CLRBACK_FLG;	
		break;

	case EVN_POST_CLOSE:
		break;
	}
	return ret;
}

